import aspose.words as aw
import os

def pngToWord(filename:str,path:str):
    # 創建文檔
    doc = aw.Document()
    # 創建文檔 builder and initialize it with document object
    builder = aw.DocumentBuilder(doc)
    # SVG 文件的路徑
    fileName = filename
    # 將 SVG 圖像插入文檔
    shape = builder.insert_image(fileName)
    # 可選的
    # 計算最大寬度和高度並更新頁面設置 
    # 裁剪文檔以適合圖片的大小。
    pageSetup = builder.page_setup
    pageSetup.page_width = shape.width
    pageSetup.page_height = shape.height
    pageSetup.top_margin = 0
    pageSetup.left_margin = 0
    pageSetup.bottom_margin = 0
    pageSetup.right_margin = 0
    # 另存為 PNG
    doc.save(path)


def svgToWord(dirPath:str,docPath:str):
    # 創建文檔
    doc = aw.Document()
    # 創建文檔 builder and initialize it with document object
    builder = aw.DocumentBuilder(doc)

    imagesPath =  os.listdir(dirPath)

    for images in imagesPath:
        # SVG 文件的路徑
        fileName = "{}/{}".format(dirPath, images)
        if fileName.endswith(".svg"):
            # 將 SVG 圖像插入文檔
            shape = builder.insert_image(images)
    # 可選的
    # 計算最大寬度和高度並更新頁面設置 
    # 裁剪文檔以適合圖片的大小。
    # pageSetup = builder.page_setup
    # pageSetup.page_width = shape.width
    # pageSetup.page_height = shape.height
    # pageSetup.top_margin = 0
    # pageSetup.left_margin = 0
    # pageSetup.bottom_margin = 0
    # pageSetup.right_margin = 0
    # 另存為 PNG
    doc.save(docPath)    
